﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace FileOperate
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            FileInfo fileInfo = new FileInfo("myFile.txt");
            if (fileInfo.Exists == false)
            {
                fileInfo.Create();
            }
            
            using (StreamWriter streamWriter = File.AppendText("myFile.txt"))
            {
                streamWriter.WriteLine(DateTime.Now.ToString());
            }

            //using (FileStream fileStream = new FileStream("myFile.txt", FileMode.OpenOrCreate))
            //{
            //    using (StreamWriter writer = new StreamWriter(fileStream))
            //    {
            //        writer.Write(DateTime.Now.ToString());
            //    }
            //}
            
        }
    }
}
